<!DOCTYPE html>
<html>
<head>
<title>隐患添加</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no" />
<meta charset="utf-8" />
 <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <link rel="stylesheet" href="css/weui.css"/>
    <link rel="stylesheet" href="css/example.css"/>
<style type="text/css">
    body, html,#allmap {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=cR98TwX2FnKTpANIOYhMYMot9a4ioxjc"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
</head>
        <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">隐患地点</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="number" pattern="[0-9]*" placeholder="输入隐患地点"/>
                </div>
            </div>
            <div id="allmap"></div>
<body>
</body>
</html>
<script type="text/javascript">
        // 百度地图API功能
    var map = new BMap.Map("allmap");
    var point = new BMap.Point(116.404, 39.915);
    map.centerAndZoom(point, 15);
    //创建自定义图标
    var myIcon = new BMap.Icon("http://lbsyun.baidu.com/jsdemo/img/fox.gif", new BMap.Size(300,157));
    // 编写自定义函数,创建标注
    function addMarker(point,myIcon){
      var marker = new BMap.Marker(point,{icon:myIcon});// 创建标注
      map.addOverlay(marker);// 将标注添加到地图中
      marker.addEventListener("click",getAttr);
    }
    //获取标注位置信息
    function getAttr(marker){
        var p = marker.getPosition();       //获取marker的位置
        alert("marker的位置是" + p.lng + "," + p.lat);   
    }
    // 随机向地图添加5个标注
    var bounds = map.getBounds();
    var sw = bounds.getSouthWest();
    var ne = bounds.getNorthEast();
    var lngSpan = Math.abs(sw.lng - ne.lng);
    var latSpan = Math.abs(ne.lat - sw.lat);
    for (var i = 0; i < 5; i ++) {
        var point = new BMap.Point(sw.lng + lngSpan * (Math.random() * 0.7), ne.lat - latSpan * (Math.random() * 0.7));
    addMarker(point,myIcon);
    }
</script>
